﻿using Prism.Commands;
using Prism.Mvvm;
using System.Collections.ObjectModel;
using System.Windows;
using ToDo.Shared.Models;
using ToDoDemo.Service;

namespace ToDoDemo.ViewModels
{
    public class ToDoViewModel : BindableBase
    {
        public ToDoViewModel(IToDoService service)
        {
            ToDoDtos = new ObservableCollection<DailyDto>();
            this.service = service;
            CreateToDoList();

        }
        private readonly IToDoService service;
        private ObservableCollection<DailyDto> toDoDtos;

        public ObservableCollection<DailyDto> ToDoDtos
        {
            get { return toDoDtos; }
            set { toDoDtos = value; RaisePropertyChanged(); }
        }

        async void CreateToDoList()
        {
            var todoResult = await service.GetAllAsync(new Page()
            {
                PageIndex = 0,
                PageSize = 100
            });
            if (todoResult.Status)
            {
                ToDoDtos.Clear();
                foreach (var item in todoResult.Result.Items)
                {
                    ToDoDtos.Add(item);
                }
            }

        }
    }
}
